package controller;

import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.util.Observable;
import java.util.Observer;

import model.TemperatureModel;
import model.*;
import view.*;

public class SliderController extends Controller {
	private TemperatureModel modelS;
	private SliderView viewS;
	
	public SliderController(int marginTop, int marginLeft, TemperatureModel model, SliderView view) {
		super(marginTop, marginLeft, model, view);
		modelS = model;
		viewS = view;
		if(view instanceof SliderCelsiusView) {
			viewS.initialize(marginTop, marginLeft, model, -20, 160);
			viewS.setAdjustmentListener(new SlideListenerCelsius());
		} else if(view instanceof SliderKelvinView) {
			viewS.initialize(marginTop, marginLeft, model, 253, 433);
			viewS.setAdjustmentListener(new SliderListenerKelvin());
		} else if(view instanceof SliderFahrenheitView) {
			viewS.initialize(marginTop, marginLeft, model, -4, 320);
			viewS.setAdjustmentListener(new SlideListenerFahrenheit());
		}
	}
	
	class SlideListenerCelsius implements AdjustmentListener {
		public void adjustmentValueChanged(AdjustmentEvent e) {
			modelS.setC(viewS.getTempValue());
		}
	}
	
	class SliderListenerKelvin implements AdjustmentListener {
		public void adjustmentValueChanged(AdjustmentEvent e) {
			modelS.setK(viewS.getTempValue());
		}
	}
	
	class SlideListenerFahrenheit implements AdjustmentListener {
		public void adjustmentValueChanged(AdjustmentEvent e) {
			modelS.setF(viewS.getTempValue());
		}
	}

}	
